package com.byxy.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import com.byxy.dao.UserDao;
import com.byxy.entity.User;
import com.byxy.service.UserService;

@Service
@Transactional
public class UserServiceImpl implements UserService {

	@Resource
	private UserDao userDao;

	@Override
	public void save(User u) {
		userDao.add(u);
	}

	@Override
	public User findByLoginNameAndPassword(String name, String pwd) {
//		List<User> list = userDao.find();
//		for (User u : list) {
//			if (u.getLoginName().equals(name) && u.getPassword().equals(pwd)) {
//				return u;
//			}
//		}
		Map<String,Object> map = new HashMap<>();
		map.put("loginName", name);
		map.put("password", pwd);
		List<User> list = userDao.find(map);
		if(list!=null && list.size()>0)
			return list.get(0);
		
//		List<User> list = userDao.find(map);
//		List<User> list = userDao.login(name, pwd);
//		System.out.println(list.size());
		
		return null;
	}

}
